package track2.linear;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import track2.context.Config;

public class LRFeatures implements Serializable{

	private static final long serialVersionUID = 7117271752241013237L;

	public static final double NOVALUE = -1;
	
	//click probability of a given Id
	public double[] pQueryId;
	public double[] pPurId;
	public double[] pTitleId;
	public double[] pDesId;
	public double[] pUserId;
	public double[] pAdId;
	public double[] pAderId;
	
	public LRFeatures(){
		pQueryId = new double[Config.queryIdSize];
		pPurId = new double[Config.purchaseIdSize];
		pTitleId = new double[Config.titleIdSize];
		pDesId = new double[Config.descriptionIdSize];
		pUserId = new double[Config.userIdSize];
		pAdId = new double[Config.adIdSize];
		pAderId = new double[Config.advertiserIdSize];
		
		//init all the values to -1
		for (int i = 0; i < Config.queryIdSize; i++)
			pQueryId[i] = NOVALUE;
		for (int i = 0; i < Config.purchaseIdSize; i++)
			pPurId[i] = NOVALUE;
		for (int i = 0; i < Config.titleIdSize; i++)
			pTitleId[i] = NOVALUE;
		for (int i = 0; i < Config.descriptionIdSize; i++)
			pDesId[i] = NOVALUE;
		for (int i = 0; i < Config.userIdSize; i++)
			pUserId[i] = NOVALUE;
		for (int i = 0; i < Config.adIdSize; i++)
			pAdId[i] = NOVALUE;
		for (int i = 0; i < Config.advertiserIdSize; i++)
			pAderId[i] = NOVALUE;
	}
	
	public static void putObject(LRFeatures feature, String path) {
		try {
			File file = new File(path);
			FileOutputStream fs = new FileOutputStream(file);
			ObjectOutputStream os = new ObjectOutputStream(fs);
			os.writeObject(feature);
			os.flush();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static LRFeatures getObject(String path) {
		LRFeatures feature = null;
		try {
			File file = new File(path);
			FileInputStream fs = new FileInputStream(file);
			ObjectInputStream os = new ObjectInputStream(fs);
			feature = (LRFeatures) os.readObject();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return feature;

	}

}
